/**
 * Copyright (c) 2009 blurredVision
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
 * associated documentation files (the "Software"), to deal in the Software without restriction, 
 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or 
 * substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 
 * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 
 * OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
#pragma once

#include "sg/SceneNode.h"
#include "geom/Vector.h"
#include "ITexture.h"

namespace terrain {

#define NUMDETAILS 3

class DLL_EXPORT ITerrain :
	public sg::SceneNode
{
public:

	// Sets a heightmap for the terrain
	virtual void setHeightmap(ITexture *pTexture);

	/// Gets the elevation at specific point
	const float getElevation(float x, float z);
	
	// Generates the height and the Normal of a spezific point of the Terrain
	// Return: height and normal!
	void getElevationAndNormal(const float &x, const float &z, float &height, math::Vector3 &normal);  

	virtual void setBlendmap(ITexture *pTexture);
	virtual void setDetail(ITexture *pTexture, int num);

	void loadHeightmap(const std::string &filename);

	void setScale(const math::Vector3 &scale);
	const math::Vector3& getScale() const;

	virtual math::Vector2f getSize() const;

	void setOffset(const math::Vector2f &offset);
	const math::Vector2f& getOffset() const;

	struct sTerrainVertex {
		math::Vector3  position;
		math::Vector3  normal;
		math::Vector3  tangent;
		math::Vector3  binormal;
		math::Vector2f texCoord;
	};

	math::Vector2i texelPos;

	virtual ~ITerrain(void);

	///Dennis. Moved by Torti
	/**
	*	Returns the filenames of the textures od the terrain
	*	\param _type Name of the texture: 'Heightmap', 'Diffuse', 'Detail'
	*	\param sNames Returns the array of names.
	*	\param numOfNames Returns the number of names in sNames.
	*/
	void getTextureFilename(const std::string &_type, std::vector<std::string> &_sNames) const;

protected:
	ITerrain(void);

	void updateTexPos(float x, float y);

	int imgW;
	int imgH;
	bool invX;
	bool invY;

	math::Vector2f realTexPos;
	math::Vector3  vScaleFactor;

	math::Vector2f  vOffset;
	math::Vector2f  vDetailOffset;

	// Textures
	ITexture*      m_pHeightmap;
	ITexture*      m_pBlendMap;
	ITexture*      m_pDetails1;
	ITexture*      m_pDetails2;
	ITexture*      m_pDetails3;

	ITexture       *m_pGrass;

};

} // namespace
